﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ettevotja_muudatus", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(EttevotjaMuudatus))]
    public class EttevotjaMuudatusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IEttevotjaMuudatus clazz;
        
        public EttevotjaMuudatusSerializer(IEttevotjaMuudatus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.AriregistriKood!=null) {
                Writer.WriteStartElement("ariregistri_kood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AriregistriKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Arinimi!=null) {
                Writer.WriteStartElement("arinimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Arinimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OiguslikVorm!=null) {
                Writer.WriteStartElement("oiguslik_vorm");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OiguslikVorm))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandevalisedIsikud!=null) {
                Writer.WriteStartElement("kandevalised_isikud");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandevalisedIsikud))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandevalisedSidevahendid!=null) {
                Writer.WriteStartElement("kandevalised_sidevahendid");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandevalisedSidevahendid))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandevalisedTegevusalad!=null) {
                Writer.WriteStartElement("kandevalised_tegevusalad");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandevalisedTegevusalad))).ToString());
                Writer.WriteEndElement();
            }
            for (int x = 0; ((clazz.Kanded != null) 
                        && (x < clazz.Kanded.Count)); x = (x + 1)) {
                if (clazz.Kanded[x]!=null) {
                    Writer.WriteStartElement("kanded");
                    global::Xtee.Core.SerializationMetadata metaKanded = this.GetMetaData(clazz.Kanded[x]);
                    Writer.WriteTypeAttribute(metaKanded.TypeQualifiedName.Namespace, metaKanded.TypeQualifiedName.Name);
                    metaKanded.NewSerializer(clazz.Kanded[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ariregistri_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus>ariregistri_kood");
                }
                clazz.AriregistriKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ariregistri_kood")).Value;
            }
            if (Reader.LocalName=="arinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus>arinimi");
                }
                clazz.Arinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("arinimi")).Value;
            }
            if (Reader.LocalName=="oiguslik_vorm") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus>oiguslik_vorm");
                }
                clazz.OiguslikVorm = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("oiguslik_vorm")).Value;
            }
            if (Reader.LocalName=="kandevalised_isikud") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus>kandevalised_isikud");
                }
                clazz.KandevalisedIsikud = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kandevalised_isikud")).Value;
            }
            if (Reader.LocalName=="kandevalised_sidevahendid") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus>kandevalised_sidevahendid");
                }
                clazz.KandevalisedSidevahendid = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kandevalised_sidevahendid")).Value;
            }
            if (Reader.LocalName=="kandevalised_tegevusalad") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus>kandevalised_tegevusalad");
                }
                clazz.KandevalisedTegevusalad = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kandevalised_tegevusalad")).Value;
            }
            if (Reader.LocalName=="kanded") {
                clazz.Kanded = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatuseKanne>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "kanded")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus>kanded");
                    }
                    global::Xtee.Core.SerializationMetadata metaKanded = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatuseKanne>(Reader, "ettevotja_muudatuse_kanne", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatuseKanne item = metaKanded.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatuseKanne>();
                    clazz.Kanded.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("kanded");
                        metaKanded.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
